﻿<UserControl x:Class="CredentialsManager.Views.ApplicationView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d"
             Height="300" Width="250">
    <Grid FocusManager.FocusedElement="{Binding ElementName=txtName}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0">
            <Label Margin="5">Application name</Label>
            <TextBox 
                Name="txtName"
                Margin="5"
                Text="{Binding ApplicationName, UpdateSourceTrigger=PropertyChanged}" />
        </StackPanel>
        <WrapPanel Grid.Row="1">
            <Button 
                Content="Create" 
                Grid.Column="0" 
                IsDefault="True"
                Command="{Binding CreateCommand}"
                Margin="5, 10, 5, 10">
                <Button.Style>
                    <Style TargetType="{x:Type Button}">
                        <Setter Property="IsEnabled" Value="True" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ApplicationName.Length}" Value="0">
                                <Setter Property="IsEnabled" Value="False" />
                            </DataTrigger>
                            <DataTrigger Binding="{Binding ApplicationName}" Value="{x:Null}">
                                <Setter Property="IsEnabled" Value="False" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
            <Button 
                Content="Close" 
                IsCancel="True"
                Grid.Column="1" 
                Margin="0, 10, 0, 10"
                Command="{Binding CloseCommand}" />
        </WrapPanel>
        <ListView Grid.Row="2" ItemsSource="{Binding Applications}" Margin="10" />
    </Grid>
</UserControl>
